package com.anglireports.report.bean.report;

import com.anglireports.report.bean.base.BaseBean;
import com.anglireports.report.response.util.CommonUtils;

import java.util.List;

/**
 * 报告-学生专注度
 * @author lvjilei
 * @ceateTime 2019/3/25.
 */
public class Concentration extends BaseBean{
    /**
     * 侦测到专注度为「很专注」的次数。
     */
    private Integer attention;

    /**
     * 侦测到专注度为「一般专注」的次数。
     */
    private Integer conscious;

    /**
     * 侦测到专注度为「作业中」的次数。
     */
    private Integer working;

    /**
     * 侦测到专注度为「瞌睡」的次数。
     */
    private Integer sleepy;


    public Concentration() {
    }

    public Concentration(Integer attention, Integer conscious, Integer working, Integer sleepy) {
        this.attention = attention;
        this.conscious = conscious;
        this.working = working;
        this.sleepy = sleepy;
    }

    public Integer getAttention() {
        return attention;
    }

    public void setAttention(Integer attention) {
        this.attention = attention;
    }

    public Integer getConscious() {
        return conscious;
    }

    public void setConscious(Integer conscious) {
        this.conscious = conscious;
    }

    public Integer getWorking() {
        return working;
    }

    public void setWorking(Integer working) {
        this.working = working;
    }

    public Integer getSleepy() {
        return sleepy;
    }

    public void setSleepy(Integer sleepy) {
        this.sleepy = sleepy;
    }

    /**
     * 根据计算规则计算出专注指数.
     * @return
     */
    public Float getConcentrationData(){
        return CommonUtils.getNum((float)(0 * sleepy + 33 * working + 66 * conscious + 100 * attention)
                / (sleepy + working + conscious + attention), "0.0");
    }

    /**
     * 1-20:1顆星
     21-40: 2顆星
     41-60: 3顆星
     61-80: 4顆星
     81-100: 5顆星
     * @return
     */
    public Integer getGuanzhudu(){
       Float score = this.getConcentrationData();
        if(score >= 0 && score <= 20){
            return 1;
        } else if (score >=21 && score <= 40){
            return 2;
        } else if (score >=41 && score <= 60){
            return 3;
        } else if (score >=61 && score <= 80){
            return 4;
        } else if (score >=81 && score <= 100){
            return 5;
        }
        return 0;
    }

    public static Concentration getConcentraionAvg(List<Concentration> list){
        Concentration concentration = new Concentration();
        Integer attention = 0;
        Integer consious = 0;
        Integer sleepy = 0;
        Integer working = 0;

        for (Concentration e : list){
            attention += e.getAttention();
            consious += e.getConscious();
            sleepy += e.getSleepy();
            working += e.getWorking();
        }

        concentration.setAttention(attention/list.size());
        concentration.setConscious(consious/list.size());
        concentration.setSleepy(sleepy/list.size());
        concentration.setWorking(working/list.size());
        return concentration;
    }


    public Concentration megreConcentration(Concentration megreConcentration){
        this.setAttention(this.getAttention() + megreConcentration.getAttention());
        this.setConscious(this.getConscious() + megreConcentration.getConscious());
        this.setSleepy(this.getSleepy() + megreConcentration.getSleepy());
        this.setWorking(this.getWorking() + megreConcentration.getWorking());
        return this;
    }
}
